<template>
    <div class="home-box">
      <el-form :inline="true" :model="searchForm">
		  
        <!-- <el-form-item label="工号">
          <el-input placeholder="工号"/>
        </el-form-item>

        <el-form-item label="姓名">
          <el-input placeholder="姓名" />
        </el-form-item> -->

        <!-- <el-form-item>
          <el-button
            type="primary"
            @click="getUserListA"
            style="margin-left: -16px"
          >
            查询
          </el-button>
        </el-form-item>

        <el-form-item>
          <el-button
            @click="resetGetUserListA"
            type="primary"
          >
            重置
          </el-button>
        </el-form-item> -->
        <el-form-item>
        <el-button color="#ff983f" :dark="isDark" plain icon="Download" @click="handleOut"
    >导出</el-button>
      </el-form-item>
      </el-form>
      <el-table
        :data="ScoreRuleList"
        border
        style="
          width: 100%;
          margin: 20px auto;
          border-radius: 8px;
          box-shadow: 5px 5px 10px rgba(64, 158, 255, 0.5);
        "
        :header-cell-style="{
          background: '#337ecc !important',
          color: '#ffffff',
          border: 'none !important',
        }"
      >
	  <el-table-column prop="deptName" label="部门" width="180" />
	  <el-table-column prop="positionName" label="岗位" width="180" />
		<el-table-column prop="name" label="被考核人" width="180" />
        <el-table-column prop="target" label="关键事项描述" width="180" />
        <el-table-column prop="assessorName" label="发布人" width="120" />
        <el-table-column prop="totalScore" label="O分值" width="80" />
        <el-table-column prop="keyResult" label="要求达成的目标" />
		<el-table-column prop="ins" label="考核类型" width="150"/>
        <el-table-column prop="keyWeight" label="考核分数" width="80" />
		<el-table-column prop="completionInstructions" label="完成情况说明" width="180" />
        <el-table-column prop="score" label="评分" width="80"> </el-table-column>
		<el-table-column prop="remark" label="评分说明" width="100" />
        <el-table-column prop="correctedValue" label="修正值/￥" width="100" />
        <el-table-column
      prop="state"
      label="当前状态"
      width="100"
    >
      <template #default="scope">
        <el-tag
          :type="scope.row.tag === 'Home' ? '' : 'success'"
          disable-transitions
          >{{ scope.row.state === 0 ? "未计入" : "审核通过" }}</el-tag
        >
      </template>
    </el-table-column>
        <el-table-column label="操作">
      <template #default="scope">
		  <!-- 未完成 先隐藏 -->
        <!-- <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button
        > -->
		<!-- 危险 先隐藏 -->
        <!-- <el-button
          size="small"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button
        > -->
      </template>
    </el-table-column>
      </el-table>
    </div>
    <pagination
    class="pagination"
    v-show="ScoreListPage.total > 0"
    :total="ScoreListPage.total"
    v-model:page="searchForm.page"
    v-model:limit="ScoreListPage.size"
    @pagination="handlePagination"
  />
  <Dialog
    v-model="DialogVisible"
    :close="close"
    :update="update"
    :select="select"
  ></Dialog>
</template>
<script setup>
import { ref, onBeforeMount, reactive, getCurrentInstance,watch } from "vue";
import {getEmpOkrNowPage,reDelete,getEmpOkrNowSearch} from "@/api/empOkr"
import Dialog from "./okrDialog";
import { ElMessage } from "element-plus";
import {downLoadEmpOkr} from "@/api/downExcel"

const searchForm = ref({
  empId: "",
  empName: "",
  page: 1,
  page_size: 10,
});
const ScoreListPage = ref([]);
const ScoreRuleList = ref([]);
onBeforeMount(() => {
  getEmpOkrNowPage(searchForm.value).then((data) => {
    ScoreListPage.value = data.data;
    ScoreRuleList.value = data.data.records;
  });
});
watch(
  ScoreRuleList,
  (newVal) => {
    
  },
  { deep: true }
);

const handleOut=()=>{
  downLoadEmpOkr()
}

const searchEvent=()=>{
  getEmpOkrNowSearch(searchForm.value).then((data) => {
    ScoreListPage.value = data.data;
    ScoreRuleList.value = data.data.records;
  });
}

const handlePagination=(value)=>{
  if(searchForm.value.empId==""&&searchForm.value.empName==""){
    getEmpOkrNowPage(value).then(data=>{
        ScoreListPage.value = data.data;
        ScoreRuleList.value = data.data.records;
    })
  }
  else{
    searchForm.value.page=value.page;
    searchForm.value.page_size=value.page_size
    getEmpOkrNowSearch(searchForm.value).then(data=>{
      ScoreListPage.value = data.data;
      ScoreRuleList.value = data.data.records;
    })
  } 
}

let select=reactive()
const DialogVisible = ref(false);
const handleEdit=(index,row)=>{
  DialogVisible.value = true;
  select=row
}
const handleDelete=(index,row)=>{
  reDelete({id:row.empScoreId}).then(data=>{
    if (data.code == 200) {
      ElMessage({
        message: "修正成功",
        type: "success",
      });
      update()
    } else {
      ElMessage.error("修正失败");
    }
  })
}

const update = () => {
  searchForm.value.empId=""
  searchForm.value.empName=""
  getEmpOkrNowPage(searchForm.value).then((data) => {
    if (data.code == 200) {
      ElMessage({
        message: "更新成功",
        type: "success",
      });
      ScoreListPage.value = data.data;
      ScoreRuleList.value = data.data.records;
    } else {
      ElMessage.error("更新失败");
    }
  });
};

const close=()=>{
  DialogVisible.value = false;
}
</script>

<style lang="scss" scoped>
.home-box {
  .header {
    margin-bottom: 22px;
    text-align: right;
  }

  ::v-deep .el-tag {
    margin-right: 6px;
  }

  ::v-deep .avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }
  .el-timeline-item {
    padding-bottom: 1px;
  }
  .cell {
    display: inline-block;
  }
}
.el-card {
  border-radius: 10px;
}
</style>
